package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateYearGroupNameDialog;
import pl.prv.polanie.client.dto.CSVYearGroupNameDTO;
import pl.prv.polanie.client.dto.CSYearGroupNameDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableYearGroupNames;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class YearGroupNamesList extends ObjectsList {

	TableYearGroupNames tableYearGroupNames= new TableYearGroupNames(this);
	
	public YearGroupNamesList() {
		
		CSYearGroupNameDTO[] ls = Cache.getAllYearGroupNames();
		//YearGroupNameDTO[] ats = Cache.getAllYearGroupNames();
		
		add(tableYearGroupNames);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSYearGroupNameDTO cs = ls[i];
			CSVYearGroupNameDTO csv = ViewDataProvider.getCSVYearGroupName(cs);
			
			tableYearGroupNames.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateYearGroupNameDialog catd = new CreateYearGroupNameDialog(YearGroupNamesList.this, null); 
				catd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableYearGroupNames.removeSelectedYearGroupNameFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSYearGroupName(CSYearGroupNameDTO csYearGroupName) {
//		CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(csLecturer);
		
		tableYearGroupNames.saveOrUpdateYearGroupNameInTable(csYearGroupName);
//		tableYearGroupNames.addRow(csLecturer, csv);
	}
	
	public void removeSelectdCSLecturer() {
		tableYearGroupNames.removeSelectedYearGroupNameFromTable();
	}
	
}
